# Maintainer: Daurnimator <daurnimator@archlinux.org>

pkgname=("lua-dkjson" "lua53-dkjson" "lua52-dkjson" "lua51-dkjson")
pkgver=2.6
pkgrel=1
pkgdesc='David Kolf’s Pure Lua JSON module with UTF-8 support and no external dependencies'
arch=('any')
url="http://dkolf.de/src/dkjson-lua.fsl/home"
license=('MIT')
makedepends=('luarocks'
             'lua51' 'lua52' 'lua53' 'lua' # https://github.com/luarocks/luarocks/issues/1275
            )
source=("http://dkolf.de/src/dkjson-lua.fsl/tarball/dkjson-$pkgver.tar.gz"
        "LICENSE")
sha256sums=('bd07ee4eb398aed6cf36f92423845399a5b46c15090990cc90e56d07c46f9773'
            '695b49734d1244ff236ec8785aa908883deb0f65b2356e36e8739ea06002b03c')

build() {
  cd "dkjson-$pkgver"
  for v in 5.1 5.2 5.3 5.4; do
    mkdir -p "$v/"
    luarocks make --lua-version="$v" \
      --pack-binary-rock --deps-mode=none \
      dkjson-"$pkgver"-1.rockspec
    mv dkjson-"$pkgver"-1.*.rock "$v/"
  done
}

package_lua-dkjson() {
  pkgdesc="$pkgdesc for Lua 5.4"
  optdepends=('lua-lpeg: speeds up decoding')

  install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  cd "dkjson-$pkgver"
  luarocks install --lua-version=5.4 --tree="$pkgdir/usr/" --deps-mode=none --no-manifest 5.4/*.rock
}

package_lua53-dkjson() {
  pkgdesc="$pkgdesc for Lua 5.3"
  optdepends=('lua53-lpeg: speeds up decoding')

  install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  cd "dkjson-$pkgver"
  luarocks install --lua-version=5.3 --tree="$pkgdir/usr/" --deps-mode=none --no-manifest 5.3/*.rock
}

package_lua52-dkjson() {
  pkgdesc="$pkgdesc for Lua 5.2"
  optdepends=('lua52-lpeg: speeds up decoding')

  install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  cd "dkjson-$pkgver"
  luarocks install --lua-version=5.2 --tree="$pkgdir/usr/" --deps-mode=none --no-manifest 5.2/*.rock
}

package_lua51-dkjson() {
  pkgdesc="$pkgdesc for Lua 5.1"
  optdepends=('lua51-lpeg: speeds up decoding')

  install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  cd "dkjson-$pkgver"
  luarocks install --lua-version=5.1 --tree="$pkgdir/usr/" --deps-mode=none --no-manifest 5.1/*.rock
}
